home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / mercury / _conio.c next >
Text File  |  1994-12-26  |  4KB  |  171 lines

  1. /*
  2.  
  3. MercuryInstaller コンソール入力ルーチン
  4.  
  5. */
  6.  
  7. #include<conio.h>
  8. #include<jctype.h>
  9. #include"mercury.h"
  10. /*------------------------------文字単位の処理-------------------------------*/
  11. static    int    Ungetch_buf[16];
  12. static    int    Ungetch_num = 0;
  13.  
  14. extern    void    ds_ungetch(int a)
  15. {
  16.     Ungetch_buf[Ungetch_num++] = a;
  17. }
  18.  
  19. extern    int    ds_kbhit(void)
  20. {
  21.     return (Ungetch_num || kbhit());
  22. }
  23.  
  24. extern    int    ds_getch(void)
  25. {
  26.     unsigned char    a;
  27.  
  28.     if    (Ungetch_num)
  29.         return Ungetch_buf[--Ungetch_num];
  30.  
  31. rep:
  32.     a = getch();
  33.  
  34.     if    (a=='\0' && kbhit())
  35.     {
  36.         a = getch();
  37.  
  38.         if    (0x3b<=a && a<=0x44)    /* IBM ファンクションキー */
  39.             return FKEY_F1-0x3b+a;
  40.  
  41.         if    (0x54<=a && a<=0x5d)    /* IBM Shift+ファンクション */
  42.             return FKEY_F1-0x54+a;
  43.  
  44.         switch    (a)
  45.         {
  46.         case 0x03:    return 0;    /* Ctrl+@ */
  47.         case 0x48:    return FKEY_UP;
  48.         case 0x4b:    return FKEY_RIGHT;
  49.         case 0x4d:    return FKEY_LEFT;
  50.         case 0x50:    return FKEY_DOWN;
  51.         case 0x52:    return FKEY_INS;
  52.         case 0x53:    return FKEY_DEL;
  53.         case 0x00:    return 0; /* 単にCtrl+@のキーコードが0x00で */
  54.                     /* リピートがかかっている場合を考慮 */
  55.         default:    goto rep;
  56.         }
  57.     }
  58.     else if    (a=='\x1b' && kbhit())
  59.     {
  60.         switch    (getch())
  61.         {
  62.         case 0x53:    return FKEY_F1;
  63.         case 0x54:    return FKEY_F2;
  64.         case 0x55:    return FKEY_F3;
  65.         case 0x56:    return FKEY_F4;    /* TOWNSではDELと同じコード */
  66.         case 0x57:    return FKEY_F5;
  67.         case 0x45:    return FKEY_F6;
  68.         case 0x4a:    return FKEY_F7;
  69.         case 0x50:    return FKEY_F8;    /* INSのコードでもある */
  70.         case 0x51:    return FKEY_F9;
  71.         case 0x5a:    return FKEY_F10;
  72.         case 0x44:    return FKEY_DEL;
  73.  
  74.         case 0x1b:        /* ESCにキーリピートがかかっている */
  75.             while    (kbhit())
  76.                 getch();
  77.             return 0x1b;
  78.  
  79.         default:    goto rep;
  80.         }
  81.     }
  82.  
  83.     switch    (a)
  84.     {                    /* 98のカーソルキー対策 */
  85.     case 0x08:    return FKEY_LEFT;    /* 98ではBSと←は同じコード */
  86.     case 0x0a:    return FKEY_DOWN;
  87.     case 0x0b:    return FKEY_UP;
  88.     case 0x0c:    return FKEY_RIGHT;
  89.     case 0x1c:    return FKEY_RIGHT;    /* TOWNSのカーソルキー対策 */
  90.     case 0x1d:    return FKEY_LEFT;
  91.     case 0x1e:    return FKEY_UP;
  92.     case 0x1f:    return FKEY_DOWN;
  93.     case 'E'-0x40:    return FKEY_UP;        /* ダイヤモンドカーソル */
  94.     case 'S'-0x40:    return FKEY_LEFT;
  95.     case 'D'-0x40:    return FKEY_RIGHT;
  96.     case 'X'-0x40:    return FKEY_DOWN;
  97.  
  98.     default:    return a;
  99.     }
  100. }
  101. /*---------------------------------文字列入力--------------------------------*/
  102. extern    int    ds_strinput(char *buf,unsigned len)
  103. {
  104.     int        _ctypebuf[81];
  105.     int        *ctypebuf = _ctypebuf + 1;
  106.             /* Pascalならctypebuf[-1..79]としたいところだが... */
  107.  
  108.     unsigned    l = 0;    /* 入力中の文字列の長さ */
  109.     unsigned    i;
  110.     int        c;
  111.  
  112.     _ctypebuf[0] = CT_ANK;
  113.  
  114.     while    ((c=*buf)!='\0')
  115.     {
  116.         putchar(c);
  117.  
  118.         *ctypebuf = chkctype(c,*(ctypebuf-1));
  119.  
  120.         buf++;
  121.         ctypebuf++;
  122.         l++;
  123.     }
  124.  
  125.     for    (i=l ; i<len ; i++)    putchar(' ');
  126.     for    (i=l ; i<len ; i++)    putchar('\b');
  127.  
  128. rep:
  129.  
  130.     c = ds_getch();
  131.  
  132.     if    (c=='\b' && l)
  133.     {
  134.         do
  135.         {
  136.             printf("\b \b");
  137.             l--;
  138.             buf--;
  139.         } while( *--ctypebuf==CT_KJ2 || *ctypebuf==CT_ILGL);
  140.  
  141.     }
  142.     else if    (c=='\r' || c=='\033')
  143.     {
  144.         *buf = '\0';
  145.  
  146.         return c=='\r';
  147.     }
  148.     else if    (c<0x100 && c>=' ' && l<len)
  149.     {
  150.         *ctypebuf = chkctype(c,*(ctypebuf-1));
  151.  
  152.         if    (*ctypebuf == CT_KJ1 && l==len-1)
  153.         {            /* バッファの最後に漢字の第1バイトが */
  154.             ds_getch();    /* 来た場合はその漢字全体を捨てる     */
  155.             putchar('\a');
  156.         }
  157.         else
  158.         {
  159.             l++;
  160.             *buf++ = c;
  161.             ctypebuf++;
  162.             putchar(c);
  163.         }
  164.     }
  165.     else        /* コントロールコード */
  166.         putchar('\a');
  167.  
  168.     goto rep;
  169. }
  170. /*-------------------------------End of _conio.c-----------------------------*/
  171.